title: HNSCC_VisiumST_Deconvolution
author: Emilia Puig Lombardi
date: 2024-02-01

In [ ]:
#Environment setup
library(Seurat) #4.3.0
library(ggplot2)
library(dplyr)
library(tibble)
library(gridExtra)
library(tidyr)
#library(CARD)
library(SpaCET)
library(patchwork)
In [2]:
obj <- readRDS("19h1257-1_PP_preprocessed.rds")

Pathologist annotations¶

In [3]:
# Label tumor/healthy spots adding pathologist annotations
patho.data <- read.table("Pathologist_annotation_MC_19H1257-1-PP.csv", sep=",",h=T, row.names=1)
head(patho.data)
A data.frame: 6 × 1
Pathologist.Annotation.CB.19H1257.1.PP
<chr>
AACACTTGGCAAGGAA-1Infiltrative SCC
AACAGGATTCATAGTT-1Infiltrative SCC
AACAGGTTATTGCACC-1Infiltrative SCC
AACAGGTTCACCGAAG-1inflamatory stroma
AACATCTAATGACCGG-1Infiltrative SCC
AACCAAGGTATCAGGC-1Infiltrative SCC
In [4]:
colnames(patho.data) <- "pathologist.annotations"
In [5]:
obj <- AddMetaData(obj,patho.data)
head(obj@meta.data)
A data.frame: 6 × 23
orig.identnCount_SpatialnFeature_Spatialresponselabelspercent.mitolow_outliershigh_outliersLOG_low_outliersLOG_high_outliers⋯seurat_clustersSCT_snn_res.0.3SCT_snn_res.0.5S.ScoreG2M.ScorePhaseold.identBarcodeCell_Phasepathologist.annotations
<chr><dbl><int><chr><chr><dbl><lgl><lgl><lgl><lgl>⋯<fct><fct><fct><dbl><dbl><chr><fct><chr><chr><chr>
AACACTTGGCAAGGAA-119h1257-1_PP307078949NRSelected2.035367FALSEFALSEFALSEFALSE⋯000 0.05958682 0.3212029G2M0AACACTTGGCAAGGAA-1unassignedInfiltrative SCC
AACAGGATTCATAGTT-119h1257-1_PP263338419NRSelected2.308890FALSEFALSEFALSEFALSE⋯000-0.05725855 0.1405744G2M0AACAGGATTCATAGTT-1unassignedInfiltrative SCC
AACAGGTTATTGCACC-119h1257-1_PP166326095NRSelected1.160414FALSEFALSEFALSEFALSE⋯323-0.37401155-0.2439678G1 3AACAGGTTATTGCACC-1unassignedInfiltrative SCC
AACAGGTTCACCGAAG-119h1257-1_PP209906931NRSelected1.257742FALSEFALSEFALSEFALSE⋯323-0.37595794-0.2896387G1 3AACAGGTTCACCGAAG-1unassignedinflamatory stroma
AACATCTAATGACCGG-119h1257-1_PP227637336NRSelected1.287177FALSEFALSEFALSEFALSE⋯212-0.32464648-0.2756775G1 2AACATCTAATGACCGG-1unassignedInfiltrative SCC
AACCAAGGTATCAGGC-119h1257-1_PP169516843NRSelected3.368533FALSEFALSEFALSEFALSE⋯707 0.03020539-0.1221090S 7AACCAAGGTATCAGGC-1unassignedInfiltrative SCC
In [7]:
# plot sample annotations
options(repr.plot.width = 8, repr.plot.height = 7)
SpatialPlot(obj, group.by = "pathologist.annotations",pt.size=3, image.alpha=0) + 
scale_fill_brewer(palette="Set3") +
theme(legend.position = "right")
Scale for fill is already present.
Adding another scale for fill, which will replace the existing scale.
No description has been provided for this image
In [8]:
#Plots of number of read of each sample -> "Tumor" sample (grey) really high in features and counts and thus was excluded due to techinical processing issues 
plot1 <- VlnPlot(obj, features = "nCount_Spatial", group.by = "pathologist.annotations", pt.size = 0.5)  & theme(axis.title.x = element_blank())
plot2 <- SpatialFeaturePlot(obj, features = "nCount_Spatial", pt.size.factor = 2.5) + theme(legend.position = "right")
plot3 <- VlnPlot(obj, features = "nFeature_Spatial", group.by = "pathologist.annotations", pt.size = 0.5)  & theme(axis.title.x = element_blank())
plot4 <- SpatialFeaturePlot(obj, features = "nFeature_Spatial", pt.size.factor = 2.5) + theme(legend.position = "right")
In [9]:
options(repr.plot.width = 20, repr.plot.height = 7)
wrap_plots(plot1, plot2)
wrap_plots(plot3, plot4)
No description has been provided for this image
No description has been provided for this image

TCGA-based CNA+expression spaCET deconvolution¶

In [10]:
SpaCET_obj <- convert.Seurat(obj)
In [11]:
SpaCET_obj <- SpaCET.quality.control(SpaCET_obj)
options(repr.plot.width = 8, repr.plot.height = 4)
SpaCET.visualize.spatialFeature(SpaCET_obj, spatialType = "QualityControl", spatialFeatures=c("UMI","Gene"))
[1] "0 spots are removed."
[1] "2204 spots are kept."
No description has been provided for this image
In [12]:
SpaCET_obj <- SpaCET.deconvolution(SpaCET_obj, cancerType="HNSC", coreNo=1)
[1] "Stage 1. Infer malignant cell fraction."
[1] "Stage 1 - Step 1. Clustering."
Warning message:
“package ‘Matrix’ was built under R version 4.2.3”
[1] "Stage 1 - Step 2. Find tumor clusters."
[1] "                  > Use CNA signature: HNSC"
[1] "Stage 1 - Step 3. Infer malignant cells."
[1] "Stage 2. Hierarchically deconvolve non-malignant cell fraction."
[1] "Stage 2 - Level 1. Estimate the major lineage."
[1] "Stage 2 - Level 2. Estimate the sub lineage."
In [13]:
SpaCET_obj@results$deconvolution$propMat[1:13,1:6]
A matrix: 13 × 6 of type dbl
47x7149x4328x8651x4167x5538x104
Malignant7.862372e-017.042460e-012.884334e-011.874085e-016.734993e-027.408492e-01
CAF5.180743e-026.460217e-021.037491e-015.193159e-015.487440e-013.506743e-08
Endothelial2.745116e-027.446003e-022.728479e-024.654161e-022.095367e-016.985626e-07
Plasma1.674682e-028.087783e-081.272769e-021.580214e-032.798907e-033.240615e-03
B cell4.927843e-071.813102e-061.233538e-027.221386e-065.745121e-062.372215e-04
T CD41.196220e-054.511230e-077.841735e-025.183198e-061.964775e-035.202394e-06
T CD84.867894e-072.880862e-078.309418e-072.871083e-053.145019e-074.702601e-08
NK3.449001e-095.264873e-077.429265e-062.097969e-066.343544e-096.016011e-03
cDC7.705822e-032.145602e-051.247545e-017.796423e-065.832765e-072.129403e-02
pDC4.646112e-031.891727e-028.885980e-027.427031e-027.498368e-032.120229e-02
Macrophage3.523450e-029.323784e-022.248861e-023.064548e-021.328065e-011.024287e-02
Mast4.805492e-057.216780e-051.267574e-031.521700e-073.527904e-033.975927e-02
Neutrophil4.709394e-096.741038e-032.396733e-011.401811e-012.575692e-025.362471e-02
In [14]:
SpaCET.visualize.spatialFeature(
  SpaCET_obj, 
  spatialType = "CellFraction", 
  spatialFeatures=c("Malignant","CAF")
)
No description has been provided for this image
In [15]:
# Identify the Tumor-Stroma Interface
SpaCET_obj <- SpaCET.identify.interface(SpaCET_obj)
# Visualize the Interface
options(repr.plot.width = 6, repr.plot.height = 5)
SpaCET.visualize.spatialFeature(SpaCET_obj, spatialType = "Interface", spatialFeature = "Interface")
No description has been provided for this image
In [ ]:
# further deconvolve malignant cell states
SpaCET_obj <- SpaCET.deconvolution.malignant(SpaCET_obj, coreNo = 1)
In [18]:
options(repr.plot.width = 15, repr.plot.height = 3)
SpaCET.visualize.spatialFeature( 
  SpaCET_obj, 
  spatialType = "CellFraction", 
  spatialFeatures=c("Malignant","Malignant cell state A","Malignant cell state B","Malignant cell state C"), 
  nrow=1
)
No description has been provided for this image
In [19]:
# Add deconvolution results as propMatFromSpaCET assay to the Seurat object
obj <- addTo.Seurat(SpaCET_obj, obj)
head(obj$propMatFromSpaCET@data, 3)
A matrix: 3 × 2204 of type dbl
AACACTTGGCAAGGAA-1AACAGGATTCATAGTT-1AACAGGTTATTGCACC-1AACAGGTTCACCGAAG-1AACATCTAATGACCGG-1AACCAAGGTATCAGGC-1AACCACTGCCATAGCC-1AACCAGAATCAGACGT-1AACCGCCAGACTACTT-1AACCTGACAGTGCCGC-1⋯TGTTACCTATTGGACA-1TGTTCAGAACGGTGTA-1TGTTCATAGTATGACG-1TGTTCCTCACATTAAT-1TGTTCTGCTCTGTCGT-1TGTTGCGTCCAAGATT-1TGTTGGAACCTTCCGC-1TGTTGGAACGAGGTCA-1TGTTGGATGGACTTCT-1TGTTGGCCAGACCTAC-1
Malignant0.786237190.704245970.288433380.187408490.067349937.408492e-019.780381e-010.496339680.563689600.06295754⋯8.740849e-010.734992680.062957548.462665e-010.613469990.191800880.762811130.456808200.913616400.64714495
CAF0.051807430.064602170.103749060.519315920.548744033.506743e-082.410500e-070.153935450.367478710.56248189⋯1.265002e-070.138648370.574051859.289249e-070.099555060.640874290.098476900.372375650.028264410.14618739
Endothelial0.027451160.074460030.027284790.046541610.209536696.985626e-071.267138e-050.017708020.037112650.24905997⋯1.236422e-060.011478370.080896611.049998e-060.067906920.064434010.043284430.086248890.021048120.04393422
In [20]:
# Access the Tumor-Stroma Interface results to the Seurat object's metadata
interface_df <- as.data.frame(t(SpaCET_obj@results$CCI$interface))
In [21]:
head(interface_df)
A data.frame: 6 × 1
Interface
<chr>
47x71Tumor
49x43Tumor
28x86Stroma
51x41Interface
67x55Stroma
38x104Tumor
In [22]:
obj[['interface']] <- interface_df$Interface
head(obj[[]], 10)
A data.frame: 10 × 24
orig.identnCount_SpatialnFeature_Spatialresponselabelspercent.mitolow_outliershigh_outliersLOG_low_outliersLOG_high_outliers⋯SCT_snn_res.0.3SCT_snn_res.0.5S.ScoreG2M.ScorePhaseold.identBarcodeCell_Phasepathologist.annotationsinterface
<chr><dbl><int><chr><chr><dbl><lgl><lgl><lgl><lgl>⋯<fct><fct><dbl><dbl><chr><fct><chr><chr><chr><chr>
AACACTTGGCAAGGAA-119h1257-1_PP307078949NRSelected2.035367FALSEFALSEFALSEFALSE⋯00 0.05958682 0.321202942G2M0AACACTTGGCAAGGAA-1unassignedInfiltrative SCC Tumor
AACAGGATTCATAGTT-119h1257-1_PP263338419NRSelected2.308890FALSEFALSEFALSEFALSE⋯00-0.05725855 0.140574388G2M0AACAGGATTCATAGTT-1unassignedInfiltrative SCC Tumor
AACAGGTTATTGCACC-119h1257-1_PP166326095NRSelected1.160414FALSEFALSEFALSEFALSE⋯23-0.37401155-0.243967759G1 3AACAGGTTATTGCACC-1unassignedInfiltrative SCC Stroma
AACAGGTTCACCGAAG-119h1257-1_PP209906931NRSelected1.257742FALSEFALSEFALSEFALSE⋯23-0.37595794-0.289638662G1 3AACAGGTTCACCGAAG-1unassignedinflamatory stroma Interface
AACATCTAATGACCGG-119h1257-1_PP227637336NRSelected1.287177FALSEFALSEFALSEFALSE⋯12-0.32464648-0.275677495G1 2AACATCTAATGACCGG-1unassignedInfiltrative SCC Stroma
AACCAAGGTATCAGGC-119h1257-1_PP169516843NRSelected3.368533FALSEFALSEFALSEFALSE⋯07 0.03020539-0.122109011S 7AACCAAGGTATCAGGC-1unassignedInfiltrative SCC Tumor
AACCACTGCCATAGCC-119h1257-1_PP370959652NRSelected2.439682FALSEFALSEFALSEFALSE⋯01 0.23181981 0.033571624S 1AACCACTGCCATAGCC-1unassignedInfiltrative SCC Tumor
AACCAGAATCAGACGT-119h1257-1_PP273748500NRSelected1.950756FALSEFALSEFALSEFALSE⋯12-0.01713912-0.010217463G1 2AACCAGAATCAGACGT-1unassignedpoorly differentiated SCC areaInterface
AACCGCCAGACTACTT-119h1257-1_PP218307737NRSelected1.749885FALSEFALSEFALSEFALSE⋯10-0.02611881 0.003792991G2M0AACCGCCAGACTACTT-1unassignedinterface ISCC/stroma Tumor
AACCTGACAGTGCCGC-119h1257-1_PP117705355NRSelected1.257434FALSEFALSEFALSEFALSE⋯12-0.15520014-0.215534806G1 2AACCTGACAGTGCCGC-1unassignedinterface ISCC/stroma Stroma
In [23]:
saveRDS(SpaCET_obj,"19h1257-1-PP_spaCET.rds")
In [25]:
Seurat::DefaultAssay(obj) <- "propMatFromSpaCET"
Seurat::SpatialFeaturePlot(obj, features = c("Malignant", "Malignant cell state A","Malignant cell state B",
                                            "Malignant cell state C"),
                          pt.size=3, ncol=4)
No description has been provided for this image
In [27]:
options(repr.plot.width = 15, repr.plot.height = 7)
plot1 <- Seurat::SpatialFeaturePlot(obj, features = c("Malignant"),pt.size=3)
plot2 <- SpatialPlot(obj, group.by = "pathologist.annotations",pt.size=3) + 
scale_fill_brewer(palette="Set3") +
theme(legend.position = "right") 
wrap_plots(plot1, plot2)
Scale for fill is already present.
Adding another scale for fill, which will replace the existing scale.
No description has been provided for this image
In [28]:
spaCET.props = as.data.frame(t(obj[["propMatFromSpaCET"]]@data))
In [29]:
obj <- AddMetaData(object = obj, metadata = spaCET.props)
In [30]:
#Assign unique label for cell type: Malignant if score>0.7, else second highest proportion label
get_cell_type <- function(proportions) {
    max_idx <- which.max(proportions)
    if (names(proportions)[max_idx] == 'Malignant') {
        if (proportions[max_idx] > 0.7) {
            return(names(proportions)[max_idx])
        } else {
            return('Epithelial')  # Assign 'Epithelial' as the label
        }
    } else {
        return(names(proportions)[max_idx])
    }
}
In [32]:
max_cell_type <- apply(obj@meta.data[, c("Malignant","CAF","Endothelial","Plasma","B cell","T CD4","T CD8","NK","cDC","pDC","Macrophage","Mast","Neutrophil","Unidentifiable","B cell naive","B cell non-switched memory","B cell switched memory","B cell exhausted","T CD4 naive","Th1","Th2","Th17","Tfh","Treg","T CD8 naive","T CD8 central memory","T CD8 effector memory","T CD8 effector","T CD8 exhausted","cDC1 CLEC9A","cDC2 CD1C","cDC3 LAMP3","Macrophage M1","Macrophage M2","Macrophage other","Malignant cell state A","Malignant cell state B","Malignant cell state C")], 1, function(x) get_cell_type(x))
In [33]:
obj@meta.data$spaCET.cellType <- max_cell_type
In [40]:
SpatialDimPlot(obj, label = F,group.by = 'spaCET.cellType', label.size = 3, pt.size=3,image.alpha=0.3)
No description has been provided for this image
In [43]:
# Normally I would correct based on pathologist annotations but this slide needs to be reviewed!
#obj$is_cancer_cell <- ifelse(obj$Malignant > 0.65 & obj$pathologist.annotations %in% c("Infiltrative SCC","In situ Carcinoma") , "1", "0")
In [41]:
obj$is_cancer_cell <- ifelse(obj$Malignant > 0.7, "1", "0")
In [42]:
plot1 <- SpatialDimPlot(obj, label = TRUE,group.by = 'is_cancer_cell', label.size = 3, pt.size=3)
plot2 <- SpatialDimPlot(obj, label = TRUE,group.by = 'interface', label.size = 3, pt.size=3)
#plot3 <- SpatialPlot(obj, group.by = "pathologist.annotations", label.size = 3)
#wrap_plots(plot2,plot1,plot3)
wrap_plots(plot2,plot1)
Scale for fill is already present.
Adding another scale for fill, which will replace the existing scale.
Scale for fill is already present.
Adding another scale for fill, which will replace the existing scale.
No description has been provided for this image
In [43]:
saveRDS(obj,"19h1257-1-PP_deconvoluted.rds")
In [45]:
options(repr.plot.width = 7, repr.plot.height = 5)
DimPlot(obj, reduction = "umap", group.by = "spaCET.cellType")
No description has been provided for this image